package com.yiren.dbaa.module.practice_set.map.view.dialog;

import android.app.Activity;

import com.yiren.backstage.config.api.LoadConfigApi;
import com.yiren.backstage.config.bean.device.StationParamConfigBean;
import com.yiren.dbaa.constant.G;
import com.yiren.dbaa.view.dialog.CustomDialog;
import com.yiren.dbaa.view.toast.MessageBox;

import org.apache.commons.lang.StringUtils;

/**
 * @author lwb
 * @date : 2022/6/1 15:04
 * @description: 采集弹出框
 */
public class MapCollectDialog {

    private Activity activity;
    private StationParamConfigBean stationParamConfig;

    public MapCollectDialog(Activity activity) {
        this.activity = activity;
        stationParamConfig = LoadConfigApi.loadStationParamConfig(activity);
    }

    /**
     * 显示是否更换设备提示框
     */
    public void showChangeDeviceDialog(OnCollectDialogListener dialogListener) {
        String stationId = stationParamConfig.getBaseStationId();
        String stationName = stationParamConfig.getBaseStationName();
        if (G.isWarnChangeDevice) {
            dialogListener.onDialogSure();
        } else {
            if (StringUtils.isEmpty(stationId + stationName)) {
                MessageBox.show(activity, "当前没有连接的基站！");
            } else {
                G.isWarnChangeDevice = true;
                String msg1 = "1、您当前连接的基站是:" + stationId + "(" + stationName + ")\r\n";
                String msg2 = stationParamConfig.isBaseCalibration() ? "" : "2、您当前连接的基站未标定，采集的轨迹将无法实现共享!!\r\n";
                String msg3 = (stationParamConfig.isBaseCalibration() ? "2、" : "3、") + "当前是否有更换工业电脑采集，如有请先将轨迹恢复默认，再采集，否则以前采集的轨迹会被覆盖";
                CustomDialog.Builder builder = new CustomDialog.Builder(activity);
                builder.setTitle("温馨提示");
                builder.setMessage(msg1 + msg2 + msg3);
                builder.setPositiveButton("是", (dialog, which) -> {
                    dialog.dismiss();
                    MessageBox.show(activity, "请先将轨迹恢复默认，再采集！");
                });
                builder.setNegativeButton("否", (dialog, which) -> {
                    dialog.dismiss();
                    dialogListener.onDialogSure();
                });
                if (!activity.isFinishing()) {
                    builder.create().show();
                }
            }
        }
    }


    /**
     * 删除通用对话框
     */
    public void doDeleteCustom(OnCollectDialogListener dialogListener) {
        CustomDialog.Builder builder = new CustomDialog.Builder(activity);
        builder.setTitle("温馨提示");
        builder.setMessage("删除后不可恢复\n确定删除吗?");
        builder.setPositiveButton("删除", (dialog, which) -> {
            dialog.dismiss();
            dialogListener.onDialogSure();
        });
        builder.setNegativeButton("取消", (dialog, which) -> dialog.dismiss());
        builder.create().show();
    }

    /**
     * 确定按钮点击回调
     */
    public interface OnCollectDialogListener {
        void onDialogSure();
    }

}
